# 暴力解法
class Solution:
    def maximumEnergy(self, energy: List[int], k: int) -> int:
        max_energy = -inf
        for i in range(len(energy)):
            temp = 0
            while i < len(energy):
                temp += energy[i]
                i += k
                if i >= len(energy):
                    max_energy = max(max_energy, temp)
        return max_energy
# 后缀和
class Solution:
    def maximumEnergy(self, energy: List[int], k: int) -> int:
        n = len(energy)
        ans = -inf
        for i in range(n - k, n):
            suf_sum = accumulate(energy[j] for j in range(i, -1, -k))
            ans = max(ans, max(suf_sum))
        return ans
# 
class Solution:
    def maximumEnergy(self, energy: List[int], k: int) -> int:
        for i in range(len(energy) - k - 1, -1, -1):
            energy[i] += energy[i + k]
        return max(energy)